home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-02-07 | 10.9 KB | 371 lines | [TEXT/MPS ] |
- {[j=20/57/1$]}
-
- {-------------------------------------------------------------------------------
- #
- # Apple Macintosh Developer Technical Support
- #
- # Code to implement application utilities
- #
- # Program: ProcDoggie
- # File: UGlobals.inc1.p - Pascal Implementation
- #
- # by: Forrest Tanaka
- #
- # Copyright © 1988-1991 Apple Computer, Inc.
- # All rights reserved.
- #
- -------------------------------------------------------------------------------}
- {[j=20/57/1$] Pasmat Options}
- {$R-}
-
-
- (*******************************************************************************
- * Constants
- *******************************************************************************)
-
- CONST
- rOKAlertID = 6010; {Resource ID of alert with OK button}
- rOKCancelAlertID = 6011; {Resource ID of alert with OK and Cancel buttons}
-
- rIconSuiteID = 128; {Resource ID of application icon suite}
- rAppNameString = 0; {Resource ID of application name}
- rAboutAlert = 258; {Resource ID of About alert}
-
-
- (*******************************************************************************
- * Variables
- *******************************************************************************)
-
- VAR
- gNotification: NMRec; {Notification record}
-
-
- {$S Main}
- (*******************************************************************************
- * Public: DoQuit
- *
- * The gQuitting global variable is set to TRUE. This causes the main event loop
- * to terminate on the next iteration.
- *******************************************************************************)
-
- PROCEDURE DoQuit;
-
- BEGIN
- gQuitting := TRUE
- END;
-
-
- {$S Main}
- (*******************************************************************************
- * Private: NotifyAlert - Present a notification for an alert
- *
- * This routine is called to present a notification to the user in the form of a
- * flashing icon in the application menu whenever an alert from this program is
- * displayed. It’s only necessary to present a notification if this application
- * is in the background, so the first check that’s done is to compare our own
- * process serial number against the process serial number of the foreground
- * process. If they’re the same, then this application is in the foreground and
- * no notification is needed. If they’re not the same, then the notification is
- * presented.
- *
- * After this application is brought to the front and the alert is dismissed this
- * notification is removed by the routine that calls NotifyAlert.
- *******************************************************************************)
-
- PROCEDURE NotifyAlert;
-
- VAR
- iconSuite: Handle; {Handle to the icon suite}
- osEvent: EventRecord; {OS event for resume}
- error: OSErr;
-
- PROCEDURE RecoverError (errorCode: OSErr);
-
- BEGIN
- EXIT (NotifyAlert)
- END;
-
- BEGIN
- (* If this application isn’t in front, post a notification *)
- IF NOT gWereInFront THEN
- BEGIN
- (* Get the small icon for this application *)
- iconSuite := Get1Resource ('SICN', rIconSuiteID);
- WITH gNotification DO
- BEGIN
- (*WITH*)qType := ORD (nmtype);
- (*WITH*)nmMark := 1;
- (*WITH*)nmIcon := iconSuite;
- (*WITH*)nmSound := Handle(-1);
- (*WITH*)nmStr := NIL;
- (*WITH*)nmResp := NIL;
- (*WITH*)nmRefCon := 0
- END;
-
- (* Post the notification *)
- error := NMINstall (@gNotification);
-
- (* Wait for a resume event *)
- WHILE NOT WaitNextEvent (app4Mask, (*<*)osEvent, -1, NIL) DO
- ;
- gWereInFront := TRUE;
- error := NMRemove (@gNotification);
-
- (* Notification blows away pending update events, so force *)
- InvalRect (FrontWindow^.portRect);
- END
- END;
-
-
- {$S Main}
- (*******************************************************************************
- * Public: ShowStopAlert
- *
- * NotifyAlert is called to present a notification to the user in case this
- * application is in the background at the time of the alert. This routine then
- * removes the notification after StopAlert is called.
- *******************************************************************************)
-
- FUNCTION ShowStopAlert (messageClass: Integer;
- messageIndex: Integer): Integer;
-
- VAR
- aMessage: Str255; {Contents of message to place in alert}
-
- BEGIN
- (* Put the specified message into the dialog parameter text *)
- GetIndString ((*<*)aMessage, messageClass, messageIndex);
- ParamText (aMessage, '', '', '');
-
- (* Show the stop alert *)
- InitCursor;
- NotifyAlert;
- ShowStopAlert := StopAlert (rOKAlertID, NIL);
- END;
-
-
- {$S Main}
- (*******************************************************************************
- * Public: ShowCautionOKCancelAlert
- *
- * NotifyAlert is called to present a notification to the user in case this
- * application is in the background at the time of the alert. This routine then
- * removes the notification after ShowCautionOKCancelAlert is called.
- *******************************************************************************)
-
- FUNCTION ShowCautionOKCancelAlert (messageClass: Integer;
- messageIndex: Integer): Integer;
-
- VAR
- aMessage: Str255; {Contents of message to place in alert}
-
- BEGIN
- (* Put the specified message into the dialog parameter text *)
- GetIndString ((*<*)aMessage, messageClass, messageIndex);
- ParamText (aMessage, '', '', '');
-
- (* Show the stop alert *)
- InitCursor;
- NotifyAlert;
- ShowCautionOKCancelAlert := CautionAlert (rOKCancelAlertID, NIL)
- END;
-
-
- {$S Main}
- (*******************************************************************************
- * Public: ShowCautionOKAlert
- *
- * NotifyAlert is called to present a notification to the user in case this
- * application is in the background at the time of the alert. This routine then
- * removes the notification after ShowCautionOKAlert is called.
- *******************************************************************************)
-
- FUNCTION ShowCautionOKAlert (messageClass: Integer;
- messageIndex: Integer): Integer;
-
- VAR
- aMessage: Str255; {Contents of message to place in alert}
- error: OSErr;
-
- BEGIN
- (* Put the specified message into the dialog parameter text *)
- GetIndString ((*<*)aMessage, messageClass, messageIndex);
- ParamText (aMessage, '', '', '');
-
- (* Show the stop alert *)
- InitCursor;
- NotifyAlert;
- ShowCautionOKAlert := CautionAlert (rOKAlertID, NIL);
- error := NMRemove (@gNotification)
- END;
-
-
- {$S Main}
- (*******************************************************************************
- * Public: ShowAboutBox
- *
- * The name and the version number of this application are retrieved from
- * resources. They’re then displayed in the About box using the ParamText
- * mechanism.
- *******************************************************************************)
-
- PROCEDURE ShowAboutBox;
-
- VAR
- appNameRes: StringHandle; {Handle to name of application}
- curVersion: VersRecHndl; {Handle to version record of this app}
- appName: Str255; {Name of this application}
- verNum: Str255; {Long version number of this application}
- itemHit: Integer; {Item number of clicked alert item; ignored}
-
- BEGIN
- (* Get the name of this application *)
- appNameRes := GetString (rAppNameString);
- IF appNameRes <> NIL THEN
- appName := appNameRes^^
- ELSE
- appName := '?';
-
- (* Get the version information of this application *)
- curVersion := VersRecHndl (Get1Resource ('vers', 1));
- IF curVersion <> NIL THEN
- (* Get the long version number *)
- verNum := StringPtr(ORD(@curVersion^^.shortVersion) +
- ORD(curVersion^^.shortVersion[0]) + 1)^
- ELSE
- verNum := '?';
-
- (* Show the About alert *)
- ParamText(appName, verNum, '', '');
- itemHit := Alert (rAboutAlert, NIL);
- END;
-
-
- {$S Main}
- (*******************************************************************************
- * Public: CreateWindow
- *
- * A WindowRecord is allocated on the heap before GetNewWindow is called. This
- * is done to reduce heap fragmentation.
- *******************************************************************************)
-
- FUNCTION CreateWindow (windowTmplID: Integer): WindowPtr;
-
- VAR
- windStore: Ptr; {Pointer to window record}
- aWindow: WindowPtr; {Pointer to the new window}
- qdVersion: LongInt; {Version of QuickDraw on this machine}
- result: OSErr;
-
- PROCEDURE RecoverError (error: Integer);
-
- BEGIN
- IF aWindow <> NIL THEN
- CloseWindow (aWindow);
- IF windStore <> NIL THEN
- DisposPtr (windStore);
- gError := error;
- CreateWindow := NIL;
- EXIT (CreateWindow)
- END;
-
- BEGIN
- windStore := NIL;
- aWindow := NIL;
-
- (* Allocate window record *)
- windStore := NewPtrMargin (SIZEOF (WindowRecord), kAllocApp,
- NOT kAllocClr);
-
- (* Create the new window *)
- IF windStore = NIL THEN
- RecoverError (memFullErr)
- ELSE
- BEGIN
- (* Create the new window *)
- result := Gestalt (gestaltQuickdrawVersion, (*<*)qdVersion);
- IF qdVersion = gestaltOriginalQD THEN
- aWindow := GetNewWindow (windowTmplID, windStore, WindowPtr(-1))
- ELSE
- aWindow := GetNewCWindow (windowTmplID, windStore,
- WindowPtr(-1));
- IF FailLowMemory (0) THEN
- RecoverError (memFullErr)
- ELSE IF ResError <> noErr THEN
- IF ResError = memFullErr THEN
- RecoverError (memFullErr)
- ELSE IF (ResError = noErr) | (ResError = resNotFound) THEN
- RecoverError (resNotFound)
- ELSE
- RecoverError (dsSysErr);
-
- SetPort (aWindow);
- SetWRefCon (aWindow, 0)
- END;
- CreateWindow := aWindow
- END;
-
-
- {$S Main}
- (*******************************************************************************
- * Public: CreateDialog
- *
- * A DialogRecord is allocated on the heap before GetNewWindow is called. This
- * is done to reduce heap fragmentation.
- *******************************************************************************)
-
- FUNCTION CreateDialog (dialogTmplID: Integer): DialogPtr;
-
- VAR
- dlogStore: Ptr; {Pointer to dialog record}
- aDialog: DialogPtr; {Pointer to the new dialog window}
- qdVersion: LongInt; {Version of QuickDraw on this machine}
- result: OSErr;
-
- PROCEDURE RecoverError (error: Integer);
-
- BEGIN
- IF aDialog <> NIL THEN
- CloseWindow (aDialog);
- IF dlogStore <> NIL THEN
- DisposPtr (dlogStore);
- gError := error;
- CreateDialog := NIL;
- EXIT (CreateDialog)
- END;
-
- BEGIN
- dlogStore := NIL;
- aDialog := NIL;
-
- (* Allocate window record *)
- dlogStore := NewPtrMargin (SizeOf (DialogRecord), kAllocApp,
- NOT kAllocClr);
-
- (* Create the new window *)
- IF dlogStore = NIL THEN
- RecoverError (memFullErr)
- ELSE
- BEGIN
- result := Gestalt (gestaltQuickdrawVersion, (*<*)qdVersion);
- IF qdVersion = gestaltOriginalQD THEN
- aDialog := GetNewWindow (dialogTmplID, dlogStore, WindowPtr(-1))
- ELSE
- aDialog := GetNewCWindow (dialogTmplID, dlogStore,
- WindowPtr(-1));
- IF FailLowMemory (0) THEN
- RecoverError (memFullErr)
- ELSE IF ResError <> noErr THEN
- IF ResError = memFullErr THEN
- RecoverError (memFullErr)
- ELSE IF (ResError = noErr) | (ResError = resNotFound) THEN
- RecoverError (resNotFound)
- ELSE
- RecoverError (dsSysErr);
-
- SetPort (aDialog);
- SetWRefCon (aDialog, 0)
- END;
- CreateDialog := aDialog
- END;
-